<div class="table-tools">
    <a href="__URL__/addUI" class="btn btn-info" title="添加赛事"><i class="fa fa-copy"></i> 添 加 </a>
    <!--<button type="submit" class="btn btn-primary" title="删除勾选的资源"><i class="glyphicon glyphicon-remove"></i> 删 除 </button>-->
    <!--<button type="button" class="btn btn-success" title="重新排序资源" onclick="sortQuestions()"><i class="fa fa-copy"></i> 重 排 </button>-->
    <form class="form-inline" method="post" action="__URL__/index" id="search_form"  role="form">
        <input type="hidden" name="pagenum" id="pagenum_hidden" value="{$page.pagenum}">
        <input type="hidden" name="count" value="{$recordcount}">
        <div class="form-group">
            <input type="text" name="id" value="{$id}" placeholder="请输入赛事id">
            <select  name="region" id="region" class="form-control">
                <switch name="region">
                    <case value="-1">
                        <option value="-1" selected>战区</option>
                        <option value="1">微信</option>
                        <option value="0">QQ</option>
                    </case>
                    <case value="0">
                        <option value="-1">战区</option>
                        <option value="1">微信</option>
                        <option value="0" selected>QQ</option>
                    </case>
                    <case value="1">
                        <option value="-1">战区</option>
                        <option value="1" selected>微信</option>
                        <option value="0">QQ</option>
                    </case>
                    <default/>
                    <option value="-1" selected>战区</option>
                    <option value="1">微信</option>
                    <option value="0">QQ</option>
                </switch>
            </select>
            <select  name="systems_name" id="systems_name" class="form-control">
                <switch name="systems_name">
                    <case value="-1">
                        <option value="-1" selected>系统</option>
                        <option value="1">IOS</option>
                        <option value="0">安卓</option>
                    </case>
                    <case value="0">
                        <option value="-1">系统</option>
                        <option value="1">IOS</option>
                        <option value="0" selected>安卓</option>
                    </case>
                    <case value="1">
                        <option value="-1">系统</option>
                        <option value="1" selected>IOS</option>
                        <option value="0">安卓</option>
                    </case>
                    <default/>
                    <option value="-1" selected>系统</option>
                    <option value="1">IOS</option>
                    <option value="0">安卓</option>
                </switch>
            </select>
            <select  name="model" id="model" class="form-control">
                <switch name="model">
                    <case value="-1">
                        <option value="-1" selected>比赛模式</option>
                        <option value="2">5v5</option>
                        <option value="1">3v3</option>
                        <option value="0">1v1</option>
                    </case>
                    <case value="0">
                        <option value="-1">比赛模式</option>
                        <option value="2">5v5</option>
                        <option value="1">3v3</option>
                        <option value="0" selected>1v1</option>
                    </case>
                    <case value="1">
                        <option value="-1">比赛模式</option>
                        <option value="2">5v5</option>
                        <option value="1" selected>3v3</option>
                        <option value="0">1v1</option>
                    </case>
                    <case value="2">
                        <option value="-1">比赛模式</option>
                        <option value="2" selected>5v5</option>
                        <option value="1">3v3</option>
                        <option value="0">1v1</option>
                    </case>
                    <default/>
                    <option value="-1" selected>比赛模式</option>
                    <option value="2">5v5</option>
                    <option value="1">3v3</option>
                    <option value="0">1v1</option>
                </switch>
            </select>
            <select  name="status" id="status" class="form-control">
                <switch name="status">
                    <case value="-1">
                        <option value="-1" selected>赛事状态</option>
                        <option value="4">已结束</option>
                        <option value="3">进行中</option>
                        <option value="2">等待开始</option>
                        <option value="1">报名中</option>
                        <option value="0">未开始报名</option>
                    </case>
                    <case value="0">
                        <option value="-1">赛事状态</option>
                        <option value="4">已结束</option>
                        <option value="3">进行中</option>
                        <option value="2">等待开始</option>
                        <option value="1">报名中</option>
                        <option value="0" selected>未开始报名</option>
                    </case>
                    <case value="1">
                        <option value="-1">赛事状态</option>
                        <option value="4">已结束</option>
                        <option value="3">进行中</option>
                        <option value="2">等待开始</option>
                        <option value="1" selected>报名中</option>
                        <option value="0">未开始报名</option>
                    </case>
                    <case value="2">
                        <option value="-1">赛事状态</option>
                        <option value="4">已结束</option>
                        <option value="3">进行中</option>
                        <option value="2" selected>等待开始</option>
                        <option value="1">报名中</option>
                        <option value="0">未开始报名</option>
                    </case>
                    <case value="3">
                        <option value="-1">赛事状态</option>
                        <option value="4">已结束</option>
                        <option value="3" selected>进行中</option>
                        <option value="2">等待开始</option>
                        <option value="1">报名中</option>
                        <option value="0">未开始报名</option>
                    </case>
                    <case value="4">
                        <option value="-1">赛事状态</option>
                        <option value="4" selected>已结束</option>
                        <option value="3">进行中</option>
                        <option value="2">等待开始</option>
                        <option value="1">报名中</option>
                        <option value="0">未开始报名</option>
                    </case>
                    <default/>
                    <option value="-1" selected>赛事状态</option>
                    <option value="4">已结束</option>
                    <option value="3">进行中</option>
                    <option value="2">等待开始</option>
                    <option value="1">报名中</option>
                    <option value="0">未开始报名</option>
                </switch>
            </select>
            <button  type="button" onclick="gotoPage(0)">搜索</button>
        </div>
    </form>
    <p>赛事列表</p>
</div>

<table id="users-table" class="table table-striped table-hover table-condensed datatable">
    <thead>

    <tr id="user_{$race.id}">
        <th width="50px">ID</th>
        <th>标题</th>
        <th>所需钻石</th>
        <th>奖励钻石</th>
        <th>战区</th>
        <th>系统</th>
        <th>比赛模式</th>
        <th>人数限制</th>
        <th>赛事状态</th>
        <th>是否上架</th>
        <th>操作</th>
        <!--<th width="150px">操作</th>-->
        <!--<th width="80px">排序</th>-->
    </tr>
    </thead>
    <tbody>
    <volist name="list" id="race">
        <tr id="race_{$race.id}">
            <!--<td width="50px"><input name='id[]' type="checkbox" value="{$race.id}" /></td>-->
            <td class="question-name">{$race.id}</td>
            <td class="question-name">{$race.title}</td>
            <td class="question-name">{$race.integral}</td>
            <td class="question-name">{$race.reward_integral}</td>
            <td class="question-name">
                <switch name="race.region">
                    <case value="0">
                        QQ
                    </case>
                    <case value="1">
                        微信
                    </case>
                </switch>
            </td>
            <td class="question-name">
                <switch name="race.systems_name">
                    <case value="0">
                        安卓
                    </case>
                    <case value="1">
                        IOS
                    </case>
                </switch>
            </td>
            <td class="question-name">
                <switch name="race.model">
                    <case value="0">
                        自由擂 1v1 墨家
                    </case>
                    <case value="1">
                        自由擂 3V3 长平
                    </case>
                    <case value="2">
                        自由擂 5V5 深渊
                    </case>
                    <case value="3">
                        自由擂 5V5 王者
                    </case>
                    <case value="4">
                        自由擂 5V5 征召
                    </case>
                    <case value="5">
                        输赢排位赛
                    </case>
                    <case value="6">
                        排位擂 输赢 「大」
                    </case>
                    <case value="7">
                        排位擂 输赢 「小」
                    </case>
                    <case value="8">
                        排位擂 输赢 「单」
                    </case>
                    <case value="9">
                        排位擂 输赢 「双」
                    </case>

                </switch>
            </td>
            <td class="question-name">
                <eq name="race.people_number" value="-1">
                    不限
                    <else/>
                    {$race.people_number}
                </eq>
            </td>
            <td class="question-name">
                <switch name="race.status">
                    <case value="0">
                        未开始报名
                    </case>
                    <case value="1">
                        报名中
                    </case>
                    <case value="2">
                        等待开始
                    </case>
                    <case value="3">
                        进行中
                    </case>
                    <case value="4">
                        已结束
                    </case>
                </switch>
            </td>
            <td class="question-name">
                <eq name="race.is_show" value="1">
                    <img width="20" height="20" src="__PUBLIC__/images/yes.png" data-name="is_show"
                         data-id="{$race.id}" data-value="0" onclick="changeFieldStatus(this)"/>
                    <else/>
                    <img width="20" height="20" src="__PUBLIC__/images/cancel.png" data-name="is_show"
                         data-id="{$race.id}" data-value="1" onclick="changeFieldStatus(this)"/>
                </eq>
            </td>
            <td width="150px">
                <a href="__URL__/apply?race_id={$race.id}" class="btn btn-default btn-rounded btn-condensed btn-sm" title="查看报名"><span class="fa fa-list">报名</span>
                </a>
            <a href="__URL__/editUI/{$race.id}" class="btn btn-default btn-rounded btn-condensed btn-sm" title="编辑赛事"><span class="fa fa-pencil">编辑</span>
            </a>
            <a onclick="deleteById('{$race.id}')" class="btn btn-default btn-rounded btn-condensed btn-sm" title="删除赛事"><span class="glyphicon glyphicon-remove">删除</span></a>
            </td>
            <!--<td width="80px"><input name="sort[{$race.id}]" class="sort-input" type="text" value="{$race.sort}" /></td>-->
        </tr>
    </volist>
    </tbody>
</table>
<nav style="float:right">
    <spen class="total">共 {$recordcount}条记录</spen>
    <div class="fr">
        <ul class="pagination">
            <eq name="page['pagenum']" value="1">
                <li class="disabled">
                    <else/>
                <li>
            </eq>
            <a href="#" onclick="gotoPage('1')">«</a></li>
            <foreach name="page.pagenums" item="vo">
                <eq name="page['pagenum']" value="$vo">
                    <li class="active"><a href="#">{$vo}</a></li>
                    <else/>
                    <li><a href="#" onclick="gotoPage('{$vo}')">{$vo}</a></li>
                </eq>
            </foreach>
            <eq name="page['pagenum']" value="$page.endPage">
                <li class="disabled">
                    <else/>
                <li>
            </eq>
            <a href="#" onclick="gotoPage('{$page.totalpage}')">»</a></li>
        </ul>
    </div>
</nav>
<div class="modal fade" id="my-alert" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">提示</h4>
            </div>
            <div class="modal-body" id="hint_content">
            </div>
            <div class="modal-footer">
                <button type="button" id="close_btn" class="btn btn-default" data-dismiss="modal">关闭</button>
                <!--<button type="button" class="btn btn-primary">Save changes</button>-->
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="delete_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="delete_title">提示</h4>
            </div>
            <div class="modal-body" id="delete_content">
                您确定删除该记录？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" id="delete_confirm" class="btn btn-primary">确定</button>
            </div>
        </div>
    </div>
</div>
<script>
    function gotoPage(pagenum) {
        //提交form
        $('#pagenum_hidden').val(pagenum);
        $('#search_form').submit();
    }

    function deleteById(id) {
        console.info(id);
        $("#delete_modal").modal();
        $('#delete_confirm').on('click', function(){
            $("#delete_modal").modal('hide');
            $.ajax({
                type: "GET",
                url: "__URL__/delete",
                data: {id: id},
                dataType: "json",
                success: function (data) {
                    console.info(data);
                    $("#hint_content1").empty().append(data.message);
                    $("#my-alert1").modal('show');
                    if (data.success) {
                        $('#race' + id).hide();
                        var count = '{$recordcount}';
                        count--;
                        $('.total').empty().append('共 '+count+' 条记录');
                    }
                },
                error: function (data) {
                    $("#hint_content1").empty().append('服务器忙');
                    $("#my-alert1").modal('show');
                }
            });


        })
    }
    function changeFieldStatus(obj) {
        var id = $(obj).data('id');
        var field = $(obj).data('name');
        var value = $(obj).data('value');
        $.ajax({
            type: 'POST',
            data: {id: id, field: field, value: value},
            url: "__URL__/updateField",
            dataType: "json",
            success: function (data) {
                if (data.success) {
                    if (value == 0) {
                        $(obj).data('value', '1');
                        $(obj).attr('src', '__PUBLIC__/images/cancel.png');
                    } else {
                        $(obj).data('value', '0');
                        $(obj).attr('src', '__PUBLIC__/images/yes.png');
                    }
                }
            },
            error: function (data) {
                $(".am-modal-bd").empty().append("请求超时！");
                $("#my-alert").modal();
            }
        });
    }
</script>